package com.ld.security.server.user.modules.dsp.service.impl;


import com.ld.security.common.mybatis.base.service.*;
import com.ld.security.common.mybatis.util.JdbcUtil;
import com.ld.security.server.user.modules.dsp.constant.DspDispatchConstant;
import com.ld.security.server.user.modules.dsp.mapping.DspDispatchMapping;
import com.ld.security.server.user.modules.dsp.po.UpdateDispatchStatusPo;
import com.ld.security.server.user.modules.dsp.service.IDspDispatchService;

import com.ld.security.server.user.modules.dsp.entity.DspDispatchEntity;

import com.ld.security.server.user.modules.dsp.vo.ActDipatchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class DspDispatchServiceImpl  extends ISuperServiceImpl<DspDispatchEntity>
implements
        IDspDispatchService {

@Autowired
        DspDispatchMapping dspDispatchMapping;

        @Override
        public int updateDispatchStatusPo(UpdateDispatchStatusPo po) {
                    List<DspDispatchEntity> objs =  this.listByIds(po.getIds());

                    for (DspDispatchEntity obj : objs) {
                            obj.setDispStatus(po.getDispStatus());
                            obj.setUptTime(new Date());
                            obj.getLabelMap().put("dispStatus",po.getDispStatus().getLabel());
                            dspDispatchMapping.updateById(obj);
                    }
                return objs.size();
        }

        @Override
        public List<ActDipatchVo> getActDipatch(String code) {
                ActDipatchVo vo =new ActDipatchVo();
                vo.setDispStatus(DspDispatchConstant.dispStatus.run);
                vo.setSpaceCode(code);
                return JdbcUtil.all(vo);
        }
}
